package bestv.kss.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;

import com.datastax.driver.core.*;

@Controller
public class CassBase {

	public static Session CassSession;
	public static Cluster CassCluster;
	public static String KeyspaceName;
	final static Logger logger = LoggerFactory.getLogger(CassBase.class);
	
	public CassBase() {
		if (CassSession == null) {
			String hosts = java.util.ResourceBundle.getBundle("config")
					.getString("cassandraHost");
			KeyspaceName = java.util.ResourceBundle.getBundle("config")
					.getString("keyspaceName");
			CassCluster = Cluster.builder().addContactPoint(hosts).build();
			CassSession = CassCluster.connect(KeyspaceName);
			logger.info(hosts+"--"+KeyspaceName+"--Connected");
		}
	}

	public void shutdown() {
		KeyspaceName = "";
		CassSession.close();
		CassCluster.close();
	}

}
